import React,{useEffect,useState} from 'react';
import { Breadcrumb,Button,Card,Input, Radio, Table,Image,Modal, Form, message, Popconfirm,notification,DatePicker  } from 'antd';
import { RedoOutlined,MoreOutlined,DeleteOutlined,AudioOutlined,PlusOutlined,PlusCircleOutlined  } from '@ant-design/icons';
import '../../style/tripadd.scss'
import axios from 'axios';
import { useNavigate } from 'react-router-dom';
import { add_list } from '../../utils/api2'


function TripAdd(props) {
    var navigate = useNavigate()
    const onFinish = (values) => {
        console.log(values);
        if(values.name == '' || values.con == '' || values.itinerary == '' || values.time == '' || values.time2 == '' ){
          notification.warning({message:'有行程信息未填写'})
        }else{
          add_list({name:values.name,con:values.con,itinerary:values.itinerary,Ctime:time.$y + '-' + (time.$M+1) + '-' + time.$D,Utime:time2.$y + '-' + (time2.$M+1) + '-' + time2.$D + ' ' + time2.$H + ' : ' + time2.$m}).then((res)=>{
            console.log(res.data);
          })
          notification.success({message:'行程信息添加成功'})
          navigate('/index/tripmanage')
        }
        
      };
      const config = {
        rules: [
          {
            type: 'object',
            required: true,
            message: 'Please select time!',
          },
        ],
      };
      var [time,setTime] = useState([])
      var change = (value)=>{
        console.log(value);
        setTime(value)
      }
      var [time2,setTime2] = useState({})
      var change2 = (value)=>{
        console.log(value);
        setTime2(value)
      }
    return (
        <div className='addTrip'>
             <Breadcrumb>
                <Breadcrumb.Item>
                <a href='/index/home'>
                    首页
                </a>
                </Breadcrumb.Item>
                <Breadcrumb.Item>
                <a href="/index/tripmanage">行程信息</a>
                </Breadcrumb.Item>
                <Breadcrumb.Item>
                <span>添加行程</span>
                </Breadcrumb.Item>
            </Breadcrumb>
            <div className="site-card-border-less-wrapper">
                <Card
                title="添加行程信息"
                className='card'
                bordered={false}
                style={{
                    width: 1250,
                }}
                >
            <Form
                labelCol={{ span: 6 }}
                wrapperCol={{ span: 18 }}
                onFinish={onFinish}
                className="addform"
               
                         
            >
                <Form.Item
                    label="学号"
                    name="con"
                    rules={[{ required: true, message: '输入学号' }]}
                    

                >
                    <Input placeholder='输入学号' className="input"/>
                </Form.Item>

                <Form.Item
                    label="姓名"
                    name="name"
                    rules={[{ required: true, message: '输入姓名' }]}
                    
                >
                    <Input placeholder='输入姓名' className="input"/>
                </Form.Item>

                <Form.Item
                    label="行程"
                    name="itinerary"
                    rules={[{ required: true, message: '输入行程' }]}
                    
                >
                    <Input placeholder='输入行程' className="input"/>
                </Form.Item>

                <Form.Item name="date-picker" label="日期" {...config}>
                  <DatePicker onChange={change} />
                </Form.Item>
                <Form.Item name="date-time-picker" label="添加时间" {...config}>
                  <DatePicker showTime format="YYYY-MM-DD HH:mm:ss" onChange={change2}/>
                </Form.Item>

                    <Form.Item className='submit'>
                      <Button type="primary" htmlType="submit" className='router'>
                        添加行程信息
                      </Button>
                    </Form.Item>
                  </Form>
                </Card>
            </div>
           
        </div>
    );
}

export default TripAdd;